package com.erp.erp_ui.Cost.Controller;

import com.erp.erp_entitys.Cost.req.QueryCostDetailWarehouseReq;
import com.erp.erp_entitys.Cost.vo.QueryCostDetailWarehouseVO;
import com.erp.erp_entitys.Cost.vo.QueryPlanInStoreProductInfoVo;
import com.erp.erp_servers.Cost.CostDetailService;
import com.erp.erp_ui.Cost.Service.CostDetailAllService;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zjk
 * @version 1.0
 * @description 费用明细控制层
 * @date 2020/11/25/025 23:34
 */
@Controller
@RequestMapping("cost/detail")
public class CostDetailController {
    private final CostDetailService detailService;
    private final CostDetailAllService costDetailAllService;
    /**
     * 日志
     */
    private static final Logger log= LoggerFactory.getLogger(CostDetailController.class);

    public CostDetailController(CostDetailService detailService, CostDetailAllService costDetailAllService) {
        this.detailService = detailService;
        this.costDetailAllService = costDetailAllService;
    }

    @RequestMapping("/test")
    public String test(){
        return "Main/main";
    }

    /**
     * 根据编号获取费用明细
     * @param req
     * @return
     */
    @RequestMapping("getCostDetailWarehouseList")
    @ResponseBody
    public R getCostDetailWarehouseListByPage(QueryCostDetailWarehouseReq req){
        try {
            log.info("根据编号获取费用明细");
            List<QueryCostDetailWarehouseVO> list=costDetailAllService.getCostDetailWarehouseList(req);
            return R.build(list);
        } catch (Exception e) {
            log.error("费用->根据编号获取费用明细功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 根据出运编码获取备货入库信息
     * @param invoiceCode
     * @param costCode
     * @return
     */
    @RequestMapping("getPlanInStoreInfoList")
    @ResponseBody
    public R getPlanInStoreInfo(String invoiceCode,String costCode){
        try {
            log.info("根据出运编码获取备货入库信息=invoiceCode:"+invoiceCode+" costCode:"+costCode);
            List<QueryPlanInStoreProductInfoVo> list=detailService.getPlanInStoreInfo(invoiceCode);
            return R.build(list);
        } catch (Exception e) {
            log.error("费用->根据出运编码获取备货入库信息异常=invoiceCode:"+invoiceCode,e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
}
